package com.hj.dapp.business.craft.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hj.dapp.business.craft.model.Craft;
import com.hj.dapp.business.craft.service.CraftService;
import com.hj.dapp.common.request.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.List;

/**
 * @author 胡奥程
 * @version 1.0
 * @date 2024/1/22
 */
@RestController
@RequestMapping("/craft")
public class CraftController {
    @Autowired
    private CraftService craftService;

    @GetMapping("/get/{id}")
    public Craft get(@PathVariable("id") Long id) {
        return craftService.get(id);
    }

    @PostMapping("/page")
    public IPage<Craft> page(@RequestBody PageRequest<Craft> pageRequest) {
        return craftService.page(pageRequest);
    }

    @DeleteMapping("/delete/{id}")
    public void delete(@PathVariable("id") Long id) {
        craftService.delete(id);
    }

    @PutMapping("/save")
    public void save(@RequestBody Craft craft, Principal principal) {
        craftService.save(craft,principal);
    }
    @PostMapping("/edit")
    public void edit(@RequestBody Craft craft,Principal principal) {
        craftService.edit(craft, principal);
    }
    @PostMapping("/list")
    public List<Craft> list(@RequestBody Craft craft) {
      return   craftService.list(craft);
    }

}
